Skip to content

fix(event-handler): handle aliased parameters e.g., Query(alias="categoryType") #3766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 15, 2024

Conversation

rubenfonseca
Copy link
Contributor

Issue number: #3732

Summary

Changes

Please provide a summary of what's being changed

This PR fixes a bug when handling event handler parameters that used aliases.

def test():
    app = APIGatewayRestResolver(enable_validation=True)

    class FunkyTown(BaseModel):
        parameter: str

    @app.get("/my/path")
    def my_path(
        parameter: Annotated[str | None, Query(alias="parameter1")] = None,
    ) -> Response[FunkyTown]:
        assert isinstance(app.current_event, APIGatewayProxyEvent)

        assert parameter == "value1"
        return Response(200, content_types.APPLICATION_JSON, FunkyTown(parameter=parameter))

    result = app(load_event("apiGatewayProxyEvent.json"), {})

    print(result)
    assert result["statusCode"] == 200

User experience

Please share what the user experience looks like before and after this change

After this PR, aliases should be correctly supported.

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@rubenfonseca rubenfonseca requested a review from a team February 13, 2024 21:49
@pull-request-size pull-request-size bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Feb 13, 2024
@heitorlessa
Copy link
Contributor

heitorlessa commented Feb 15, 2024

Unsure why this test is failing; works locally. Pushing a no-op code change w/ a rebase, before we investigate further.

Edit: global dict mutation race condition w/ running multiple tests.

Signed-off-by: heitorlessa <lessa@amazon.co.uk>
* develop:
  chore: cleanup, add test for single and nested
  fix(parameters): make cache aware of single vs multiple calls
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
@pull-request-size pull-request-size bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 15, 2024
@heitorlessa
Copy link
Contributor

Indeed racing condition. Reverting no-op change, and merging after CI completes all checks.

@pull-request-size pull-request-size bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 15, 2024
Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@heitorlessa heitorlessa changed the title fix(event-handler): correctly handle aliased parameters fix(event-handler): handle aliased parameters e.g., Query(alias="categoryType") Feb 15, 2024
Copy link
Contributor

@heitorlessa heitorlessa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks a lot for the fix @rubenfonseca 🙌

@sthulb sthulb merged commit f31ea17 into develop Feb 15, 2024
@sthulb sthulb deleted the rf/fix-param-alias branch February 15, 2024 09:17
@heitorlessa heitorlessa added the bug Something isn't working label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working event_handlers size/S Denotes a PR that changes 10-29 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants